n = int(input())
ts = []
for i in range(0,n):
    ts.append(list(map(int,input().split())))

    ps = [x for x in ts[i]]

    if ps[1] >= ps[0] or ps[1] >= ps[2] or ps[1] >= ps[3]:
        ts[i][1] = 999
    if ps[2] >= ps[0]:
        ts[i][2] = 999
    if ps[3] >= ps[0] or ps[3] >= ps[1] or ps[3] >= ps[2]:
        ts[i][3] = 999

for i in range(0,n):
    for j in range(i + 1,n):
        if ts[i][0] < ts[j][0] or (ts[i][0] == ts[j][0] and ts[i][1] > ts[j][1]):
            temp = ts[i]
            ts[i] = ts[j]
            ts[j] = temp

result = 400

def dfs(i,c1,c2,g,n):
    global result
    m = max(c1,c2,g)
    if m >= result:
        return

    if i >= n:
        result = m
        return
    #方案4
    if ts[i][3] != 999:
        dfs(i + 1,c1 + ts[i][3],c2 + ts[i][3],g + ts[i][3],n)

    #方案2
    if ts[i][1] != 999:
        dfs(i + 1,c1 + ts[i][1],c2 + ts[i][1],g,n)

    #方案3
    if ts[i][2] != 999:
        if c1 < c2:
            dfs(i + 1,c1 + ts[i][2],c2,g + ts[i][2],n)
        else:
            dfs(i + 1,c1,c2 + ts[i][2],g + ts[i][2],n)
    
    #方案1
    if c1 < c2:
        dfs(i + 1,c1 + ts[i][0],c2,g,n)
    else:
        dfs(i + 1,c1,c2 + ts[i][0],g,n)

dfs(0,0,0,0,n)
print(result)
